var app = getApp();
Page({
  data: {
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
    showlist:false,
    pageInfo: '',
    rest:'',
    ifdata:false,
    array: ['一月', '二月', '三月', '四月','五月', '六月', '七月', '八月','九月', '十月', '十一月', '十二月'],
    index: 0,
    data:['暂无打卡记录'],
    data2:['暂无打卡记录']
  },

  bindPickerChange: function(e) {
    this.setData({ index: e.detail.value});  
  
    this.setData({
      yuefen: e.detail.value
    })

    this.getdaka()
    this.getqingjia()
  },
 upkaoqin(id,type){
  var that =this
  wx.request({
    url: app.apiUrl + '/api/index/jswupkaoqin',
    data: {
       openid:wx.getStorageSync('openid'),
       ban:wx.getStorageSync('banci'),
       id:id,
       type:type,
    },
    method: 'POST',
    header: { 'content-type': 'application/x-www-form-urlencoded' },
    success: res=> {
          if(res.data.code == "0"){
            wx.showModal({
              title: '温馨提示',
              content: res.data.msg,
              showCancel: false
            });
          }else{
            wx.showModal({
              title: '温馨提示',
              content: res.data.msg,
              showCancel: false
            });
          }
          this.getdaka()  
    }
  })
 },
  //修改考勤
  goPage(e){
    var type = e.currentTarget.dataset.type;
    var id = e.currentTarget.dataset.id;
    if(type == 1){
      //更新上班地址
      this.upkaoqin(id,type);
    }else if(type == 2){
      //更新下班地址
      this.upkaoqin(id,type);
    }else if(type == 3){
      //补下班卡 
      wx.navigateTo({
        url: e.currentTarget.dataset.url,
      });
    }

 
},

  swichNav: function( e ) {
      console.log(e)
    var that = this;

    if( this.data.currentTab === e.target.dataset.current ) {
        return false;
    } else {
      that.setData( {
        currentTab: e.target.dataset.current
    })
      console.log(e.target.dataset.current)
        if(e.target.dataset.current == 0){
            that.getdaka()
            that.setData( { showlist: false });
        }else{
          that.getqingjia()
          that.setData( { showlist: true });
        }
    }
},
stopTouchMove:function(){
  return false;
},
bindChange: function( e ) { 
   var that = this;
    that.setData( { currentTab: e.detail.current });

},


chexiao: function (e) {
  var that =this
  wx.showModal({
    title: '',
    content: '是否确认撤销',
    success(res) {
     if (res.confirm) {
      console.log('用户点击确定')
      wx.request({
        url: app.apiUrl + '/api/index/qingjiachexiao',
        data: {
           qid:e.currentTarget.dataset.fee
        },
        method: 'POST',
        header: { 'content-type': 'application/x-www-form-urlencoded' },
        success: res=> {
          wx.showModal({
            title: '温馨提示',
            content: res.data.msg,
            showCancel: false
          });
          that.getqingjia()
        }
      })

     } else if (res.cancel) {
      console.log('用户点击取消')
     }
    }
   })

},

getdaka: function () {
  var that =this
wx.request({
  url: app.apiUrl + '/api/index/jswdakajilu',
  data: {
     openid:wx.getStorageSync('openid'),
     yuefen:that.data.index
  },
  method: 'POST',
  header: { 'content-type': 'application/x-www-form-urlencoded' },
  success: res=> {
        if(res.data.code == "0"){
          wx.showModal({
            title: '温馨提示',
            content: res.data.msg,
            showCancel: false
          });
          return false;
        }else{
      
          var len = res.data.data.length+1
          var len2 = len +1;
          if(len == 0){
            that.setData({ data: ''});
            that.setData({
              ifdata: true,
            })
          }else{
            that.setData({
              ifdata: false,
            })
            that.setData({ data: res.data.data});
          }

      
        }

  }
})
},


getqingjia: function () {
  var that =this

wx.request({
  url: app.apiUrl + '/api/index/qingjiajilu',
  data: {
     openid:wx.getStorageSync('openid'),
     yuefen:that.data.index
  },
  method: 'POST',
  header: { 'content-type': 'application/x-www-form-urlencoded' },
  success: res=> {
    
        if(res.data.data.length>0){
          that.setData({ data2: res.data.data});
          var len = res.data.data.length
          that.setData({
            ifdata: false,
            winHeight:350*len
          })
        }else{
          that.setData({ data2: ''});
          that.setData({
            ifdata: true,
            winHeight:350
          })
        }
 
  }
})
},


  onLoad: function () {
    var that = this;
    var date = new Date();

var yuefen = date.getMonth()

that.setData({ index: yuefen});


    wx.getSystemInfo( {
      success: function( res ) {
          that.setData( {
              winWidth: res.windowWidth,
          });
      }

  });
    if (!wx.getStorageSync('openid')) {
      app.error("请登录后再操作");
      return false;
    }
 
  },

  onShow:function(){
    this.getdaka()
  }






})